{% extends 'core/base.html' %}
{% load static %}

{% block title %}意见反馈 - 社区管理系统{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2>
                    <i class="fas fa-comments text-info"></i> 意见反馈
                </h2>
                <a href="{% url 'create_feedback' %}" class="btn btn-primary">
                    <i class="fas fa-plus"></i> 新建反馈
                </a>
            </div>
        </div>
    </div>

    {% if page_obj %}
    <div class="row">
        {% for feedback in page_obj %}
        <div class="col-12 mb-3">
            <div class="card feedback-card">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start">
                        <div class="flex-grow-1">
                            <div class="d-flex align-items-center mb-2">
                                <h6 class="mb-0 me-3">反馈 #{{ feedback.feedback_id }}</h6>
                                <span class="badge bg-{% if feedback.status == 'processed' %}success{% elif feedback.status == 'rejected' %}danger{% else %}warning{% endif %}">
                                    {{ feedback.get_status_display }}
                                </span>
                                {% if feedback.reward_points > 0 %}
                                <span class="badge bg-info ms-2">
                                    <i class="fas fa-coins"></i> +{{ feedback.reward_points }} 积分
                                </span>
                                {% endif %}
                            </div>
                            <p class="card-text">{{ feedback.content }}</p>
                            
                            {% if feedback.admin_reply %}
                            <div class="alert alert-light mt-3">
                                <strong><i class="fas fa-reply"></i> 管理员回复：</strong>
                                <p class="mb-0 mt-2">{{ feedback.admin_reply }}</p>
                            </div>
                            {% endif %}
                            
                            <div class="row mt-3">
                                <div class="col-md-6">
                                    <div class="text-muted small">
                                        <i class="fas fa-calendar-alt"></i> 提交时间：{{ feedback.created_at|date:"Y年m月d日 H:i" }}
                                    </div>
                                </div>
                                {% if feedback.processed_at %}
                                <div class="col-md-6">
                                    <div class="text-muted small">
                                        <i class="fas fa-check"></i> 处理时间：{{ feedback.processed_at|date:"Y年m月d日 H:i" }}
                                        {% if feedback.processed_by %}
                                        <br><i class="fas fa-user-tie"></i> 处理人：{{ feedback.processed_by }}
                                        {% endif %}
                                    </div>
                                </div>
                                {% endif %}
                            </div>
                        </div>
                        <div class="ms-3 text-center">
                            <span class="status-text">
                                {% if feedback.status == 'processed' %}
                                    已处理
                                    {% if feedback.reward_points > 0 %}
                                    <div class="reward-badge">
                                        <small class="d-block text-warning">已奖励</small>
                                    </div>
                                    {% endif %}
                                {% elif feedback.status == 'rejected' %}
                                    已拒绝
                                {% else %}
                                    处理中
                                {% endif %}
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>

    <!-- 分页 -->
    {% if page_obj.has_other_pages %}
    <nav aria-label="反馈分页">
        <ul class="pagination justify-content-center">
            {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?page=1">首页</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
                </li>
            {% endif %}

            {% for num in page_obj.paginator.page_range %}
                {% if page_obj.number == num %}
                    <li class="page-item active">
                        <span class="page-link">{{ num }}</span>
                    </li>
                {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                    </li>
                {% endif %}
            {% endfor %}

            {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">末页</a>
                </li>
            {% endif %}
        </ul>
    </nav>
    {% endif %}

    {% else %}
    <div class="row">
        <div class="col-12">
            <div class="alert alert-info text-center">
                <i class="fas fa-comments fa-3x mb-3"></i>
                <h4>还没有反馈记录</h4>
                <p>您还没有提交过任何反馈，有问题或建议请及时反馈给我们！</p>
                <a href="{% url 'create_feedback' %}" class="btn btn-primary">
                    <i class="fas fa-plus"></i> 提交反馈
                </a>
            </div>
        </div>
    </div>
    {% endif %}
    
    <!-- 图片装饰区域 - 页面底部 -->
    <div class="row mt-5">
        <div class="col-12">
            <div class="bottom-decoration text-center py-4">
                <div class="row">
                    <div class="col-md-3 mb-3">
                        <i class="fas fa-comments fa-3x text-info mb-2"></i>
                        <h6>意见反馈</h6>
                        <p class="text-muted small">您的意见是我们改进的动力</p>
                    </div>
                    <div class="col-md-3 mb-3">
                        <i class="fas fa-check-circle fa-3x text-success mb-2"></i>
                        <h6>快速处理</h6>
                        <p class="text-muted small">专业团队及时回应</p>
                    </div>
                    <div class="col-md-3 mb-3">
                        <i class="fas fa-gift fa-3x text-warning mb-2"></i>
                        <h6>积分奖励</h6>
                        <p class="text-muted small">有效反馈获得积分奖励</p>
                    </div>
                    <div class="col-md-3 mb-3">
                        <i class="fas fa-users fa-3x text-primary mb-2"></i>
                        <h6>共建社区</h6>
                        <p class="text-muted small">携手打造美好社区</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.feedback-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: box-shadow 0.3s ease;
}

.bottom-decoration {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 15px;
    border: 1px solid #dee2e6;
}

.bottom-decoration i {
    transition: transform 0.3s ease;
}

.bottom-decoration i:hover {
    transform: scale(1.1);
}

.status-text {
    font-weight: 500;
    font-size: 14px;
}
</style>
{% endblock %}
